package org.jeecg.common.modules.register.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import org.jeecg.common.modules.register.entity.RegisterPatient;
import org.jeecg.common.modules.register.entity.RegisterPayOrder;
import org.jeecg.common.modules.register.mapper.RegisterPatientMapper;
import org.jeecg.common.modules.register.service.IRegisterPatientService;
import org.jeecg.common.modules.wx.entity.WxUserinfo;
import org.jeecg.common.modules.wx.service.IWxUserinfoService;
import org.jeecg.common.util.enums.OrderTypeEnum;
import org.jeecg.common.util.enums.PayOrderStatusEnum;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: register_patient
 * @Author: jeecg-boot
 * @Date:   2021-01-26
 * @Version: V1.0
 */
@Service
public class RegisterPatientServiceImpl extends ServiceImpl<RegisterPatientMapper, RegisterPatient> implements IRegisterPatientService {
    @Resource
    private IWxUserinfoService wxUserinfoService;

    @Override
    public List<RegisterPatient> getPatientsByOpenid(String wxUserInfoId){
        LambdaQueryWrapper<RegisterPatient> patientQuery = Wrappers.lambdaQuery();
        patientQuery.eq(RegisterPatient::getWxUserinfoId,wxUserInfoId);
        patientQuery.eq(RegisterPatient::getDeleteStatus,0);  // 可见的档案
        patientQuery.orderByDesc(RegisterPatient::getCreateTime);
        return list(patientQuery);
    }

    @Override
    public RegisterPatient getPatient(String wxUserInfoId,String patientId){
        LambdaQueryWrapper<RegisterPatient> patientQuery = Wrappers.lambdaQuery();
        patientQuery.eq(RegisterPatient::getWxUserinfoId,wxUserInfoId);
        patientQuery.eq(RegisterPatient::getId,patientId);
        return getOne(patientQuery);
    }

    @Override
    public RegisterPatient getPatientOne(String patientId,Integer deleteStatus){
        LambdaQueryWrapper<RegisterPatient> patientQuery = Wrappers.lambdaQuery();
        patientQuery.eq(RegisterPatient::getId,patientId);
        patientQuery.eq(RegisterPatient::getDeleteStatus,deleteStatus); //获取可见/不可见的信息
        return getOne(patientQuery);
    }

    @Override
    public int getRegisterPatientCount(String wxUserInfoId){
        LambdaQueryWrapper<RegisterPatient> patientQuery = Wrappers.lambdaQuery();
        patientQuery.eq(RegisterPatient::getWxUserinfoId,wxUserInfoId);
        patientQuery.eq(RegisterPatient::getDeleteStatus,0);
        patientQuery.orderByDesc(RegisterPatient::getCreateTime);
        return count(patientQuery);
    }
}
